package com.sctvcloud.renhe.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.utils.ListUtils;
import com.sctvcloud.renhe.R;
import com.sctvcloud.renhe.beans.FComment;
import com.sctvcloud.renhe.beans.NewsItem;
import com.sctvcloud.renhe.ui.adapter.holder.AnchorRelateNewsHolder;
import com.sctvcloud.renhe.ui.adapter.holder.BaseAnchorHolder;
import com.sctvcloud.renhe.ui.adapter.holder.CommentHolder;
import com.sctvcloud.renhe.ui.util.IListShowData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/26 0026.
 */

public class AnchorRelateNewsAdapter extends BaseHolderAbsAdapter<IListShowData, BaseAnchorHolder<IListShowData>> {
    public AnchorRelateNewsAdapter(Context context, List list) {
        super(context, list);
    }

    @Override
    public BaseAnchorHolder<IListShowData> onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_anchor_relate, null);
        BaseAnchorHolder bah = new AnchorRelateNewsHolder(context, view);
        bah.setInternalClick(this);
        return bah;
    }

    @Override
    public AnchorRelateNewsAdapter setItemInternalClick(OnItemInternalClick itemInternalClick) {
        super.setItemInternalClick(itemInternalClick);
        return this;
    }

    @Override
    public void onBindViewHolder(BaseAnchorHolder<IListShowData> holder, int position) {
//        holder.setItemMode(position == getItemCount() - 1 ? BaseAnchorHolder.ITEMMODE_LAST : BaseAnchorHolder.ITEMMODE_NORMAL);
        super.onBindViewHolder(holder, position);
    }

    @Override
    public AnchorRelateNewsAdapter setData(List data) {
        super.setData(data);
        return this;
    }

    @Override
    public void addDatas(List list) {
        if (data == null) {
            if (ListUtils.isListValued(list)) {
                data = new ArrayList<>();
                data.addAll(list);
                notifyDataSetChanged();
            }
        } else if (list != null && list.size() > 0) {
            int fromPos = getItemCount();
            if (fromPos < 0) {
                fromPos = 0;
            }
            data.addAll(list);
            notifyItemRangeChanged(fromPos, list.size());
            notifyDataSetChanged();
        }
    }

}
